package com.jzo2o.orders.manager.handler;

import cn.hutool.core.collection.CollectionUtil;
import com.jzo2o.orders.base.model.domain.Orders;
import com.jzo2o.orders.manager.service.IOrdersManagerService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时清理未支付订单的定时任务
 */
@Slf4j
@Component
public class CancelOverTimePayOrder {

    @Resource
    private IOrdersManagerService managerService;

    @XxlJob(value = "cancelOverTimePayOrder")
    public ReturnT cancelOrderOverTimeAuto() {
        log.info("定时清理未支付订单开始");
        List<Orders> ordersList = managerService.queryOverTimePayOrdersListByCount(100);
        if (CollectionUtil.isEmpty(ordersList)){
            log.info("没有需要清理的订单，结束");
            return ReturnT.SUCCESS;
        }
        managerService.cancelOrderOverTimeAuto(ordersList);
        return ReturnT.SUCCESS;
    }
}
